package com.lmq.ocp;

/**
 * ocp package is also added.
 */
public class Ocp {
    public static void main(String[] args) {
        // test
        GraphicEditor graphicEditor = new GraphicEditor();
        graphicEditor.drawSahpe(new Rectangle());
        graphicEditor.drawSahpe(new Circle());
        graphicEditor.drawSahpe(new Triangle());


    }
}
//绘图类
// 违反OCP原则
// 新增加图形，修改地方较多

class GraphicEditor{
    public void drawSahpe(Shape s){
        if (s.m_type == 1)
            drawRectangle(s);
        else if (s.m_type == 2)
            drawCircle(s);
        else if (s.m_type == 3)
            drawTriangle(s);

    }
    public void drawRectangle(Shape r){
        System.out.println("drawing rectangle!!");
    }
    public void drawCircle(Shape r){
        System.out.println("drawing circle!!!!");
    }
    public void drawTriangle(Shape r){
        System.out.println("drawing triangle!!!");
    }

}

class Shape{
    int m_type;

}

class Rectangle extends Shape{
    Rectangle(){
        super.m_type = 1;
    }
}

class Circle extends Shape{
    Circle(){
        super.m_type = 2;
    }
}


class Triangle extends  Shape{
    Triangle(){
        super.m_type = 3;
    }
}